package com.baiyang.server.service.system.impl;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baiyang.server.dao.system.MenuDao;
import com.baiyang.server.dao.system.MenuRoleDao;
import com.baiyang.server.dao.system.UserRoleDao;
import com.baiyang.server.model.system.Menu;
import com.baiyang.server.model.system.MenuRole;
import com.baiyang.server.service.impl.BaseServiceImpl;
import com.baiyang.server.service.system.MenuService;
import com.baiyang.server.tools.Data;
import com.baiyang.server.tools.DataTool;

/**
 * 
 * @author XVX
 * BY: @Primary 注解帮助生命@Autowired优先注入的实列
 */
@Service	
public class MenuServiceImpl extends BaseServiceImpl<MenuDao, Menu>implements MenuService{
	@Autowired
	private MenuDao menuDao = null;
	@Autowired
	private MenuRoleDao menuRoleDao = null;
	@Autowired
	private UserRoleDao userRoleDao = null;
	
	@Override
	public List<Menu> getMenus(List<String> roleIds) {
		if(DataTool.isBlank(roleIds)) {
			return null;
		}
		//判断是否拥有管理员角色
		boolean flag = false;
		for (String roleId : roleIds) {
			if(Data.DataDictionary.SUPER_ADMIN_ROLE_ID.equals(roleId)) {
				flag = true;
			}
		}
		List<Menu> menus = null;
		if(flag) {
			//获取所有菜单信息
			Menu menu = new Menu();
			menu.setDel("0");
			menu.setAvailable("1");
			menus = menuDao.selectList(menu);
		}else {
			//根据角色获取菜单信息
			menus = menuRoleDao.selectByRoleIds(roleIds);
		}
		return menus;
	}




}
